
/**
 * operator new/delete 重载
 * 当new和delete被重载为全局时，C++原来的new与delete被忽略，
 * 并且重载的运算符用于所有类型（包括标准型和用户定义类型）的分配要求。
 * 
*/

#include <cstdlib>

#include <iostream>

using namespace std;

void *operator new(size_t size)
{
    cout << "Global new()\n";
    return malloc(size);
}

void *operator new[](size_t size)
{
    cout << "Global new()[]\n";
    return malloc(size);
}

void operator delete(void *ptr)
{
    cout << "Global delete()\n";
}

void operator delete[](void *ptr)
{
    cout << "Global delete()[]\n";
}

int main()
{

    int *a = new int;
    delete a;

    int *array = new int[10];
    delete[] array;


    int *da = ::new int;
    int *darray = new int[10];

    
    return 0;
}